<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RabbitMQ 消息模型与交换机类型</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.1);
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: rgba(102, 126, 234, 0.3);
        }
        
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #e0e0e0, transparent);
            margin: 3rem 0;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .exchange-card {
            position: relative;
            overflow: hidden;
        }
        
        .exchange-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #667eea, #764ba2);
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center animate-fadeInUp">
                <h1 class="text-5xl font-bold mb-6">RabbitMQ 消息模型与交换机类型</h1>
                <p class="text-xl mb-8 opacity-90 max-w-3xl mx-auto">
                    深入理解消息中间件的核心机制，掌握不同交换机类型的应用场景，构建高效可靠的分布式系统
                </p>
                <div class="flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3">
                        <i class="fas fa-exchange-alt mr-2"></i>
                        4种交换机类型
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3">
                        <i class="fas fa-route mr-2"></i>
                        灵活路由策略
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3">
                        <i class="fas fa-project-diagram mr-2"></i>
                        多种消息模型
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="mb-16 animate-fadeInUp">
            <div class="card-hover rounded-xl p-8">
                <h2 class="text-3xl font-bold mb-6 gradient-text">引言</h2>
                <p class="text-lg leading-relaxed text-gray-700 mb-4">
                    在现代分布式系统的架构设计中，消息队列已成为实现系统间异步通信的关键技术。RabbitMQ 作为最流行的消息中间件之一，提供了强大而灵活的消息路由机制。
                </p>
                <p class="text-lg leading-relaxed text-gray-700">
                    本文将深入探讨 RabbitMQ 中的消息模型与交换机类型，帮助您理解如何通过不同类型的交换机来精确路由消息，并掌握各种消息模型的使用场景。
                </p>
            </div>
        </section>

        <!-- Exchange Types Overview -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-8 text-center gradient-text">交换机类型概览</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-12">
                <div class="card-hover exchange-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-arrow-right"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-3">Direct Exchange</h3>
                    <p class="text-gray-700 mb-4">直接交换机通过精确匹配路由键来投递消息，适用于点对点的消息传递场景。</p>
                    <div class="flex items-center text-sm text-purple-600">
                        <i class="fas fa-check-circle mr-2"></i>
                        精确路由
                    </div>
                </div>
                
                <div class="card-hover exchange-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-broadcast-tower"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-3">Fanout Exchange</h3>
                    <p class="text-gray-700 mb-4">扇形交换机将消息广播到所有绑定的队列，无需考虑路由键。</p>
                    <div class="flex items-center text-sm text-purple-600">
                        <i class="fas fa-check-circle mr-2"></i>
                        消息广播
                    </div>
                </div>
                
                <div class="card-hover exchange-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-sitemap"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-3">Topic Exchange</h3>
                    <p class="text-gray-700 mb-4">主题交换机支持通配符匹配，实现灵活的消息路由规则。</p>
                    <div class="flex items-center text-sm text-purple-600">
                        <i class="fas fa-check-circle mr-2"></i>
                        模式匹配
                    </div>
                </div>
                
                <div class="card-hover exchange-card rounded-xl p-6">
                    <div class="feature-icon">
                        <i class="fas fa-tags"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-3">Headers Exchange</h3>
                    <p class="text-gray-700 mb-4">头交换机根据消息头部属性进行路由，支持复杂的匹配条件。</p>
                    <div class="flex items-center text-sm text-purple-600">
                        <i class="fas fa-check-circle mr-2"></i>
                        属性匹配
                    </div>
                </div>
            </div>

            <!-- Message Flow Diagram -->
            <div class="card-hover rounded-xl p-8">
                <h3 class="text-2xl font-bold mb-6 text-center">消息流转架构图</h3>
                <div class="mermaid">
                    graph LR
                        P[生产者] -->|发送消息| E{交换机}
                        E -->|Direct| Q1[队列1]
                        E -->|Fanout| Q2[队列2]
                        E -->|Topic| Q3[队列3]
                        E -->|Headers| Q4[队列4]
                        Q1 --> C1[消费者1]
                        Q2 --> C2[消费者2]
                        Q3 --> C3[消费者3]
                        Q4 --> C4[消费者4]
                        
                        style P fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style E fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style Q1 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                        style Q2 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                        style Q3 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                        style Q4 fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Direct Exchange Detail -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-8 gradient-text">Direct Exchange 详解</h2>
            
            <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8">
                <div class="lg:col-span-2">
                    <div class="card-hover rounded-xl p-8">
                        <h3 class="text-2xl font-bold mb-4">工作原理</h3>
                        <p class="text-gray-700 mb-6 leading-relaxed">
                            Direct Exchange 是最简单直接的交换机类型。它通过精确匹配消息的路由键（routing key）与队列绑定时指定的绑定键（binding key）来决定消息的投递目标。只有当两者完全相同时，消息才会被路由到对应的队列。
                        </p>
                        
                        <h4 class="text-xl font-semibold mb-3">核心特性</h4>
                        <ul class="space-y-3 mb-6">
                            <li class="flex items-start">
                                <i class="fas fa-check text-purple-600 mt-1 mr-3"></i>
                                <span class="text-gray-700"><strong>精确匹配：</strong>路由键必须与绑定键完全一致</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-purple-600 mt-1 mr-3"></i>
                                <span class="text-gray-700"><strong>高效路由：</strong>基于哈希表实现，查找速度快</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-purple-600 mt-1 mr-3"></i>
                                <span class="text-gray-700"><strong>多队列支持：</strong>一个交换机可以绑定多个队列</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div>
                    <div class="card-hover rounded-xl p-6">
                        <h4 class="text-xl font-bold mb-4">
                            <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                            使用场景
                        </h4>
                        <ul class="space-y-3">
                            <li class="text-gray-700">
                                <i class="fas fa-angle-right text-purple-600 mr-2"></i>
                                日志分级处理系统
                            </li>
                            <li class="text-gray-700">
                                <i class="fas fa-angle-right text-purple-600 mr-2"></i>
                                任务分发系统
                            </li>
                            <li class="text-gray-700">
                                <i class="fas fa-angle-right text-purple-600 mr-2"></i>
                                微服务间通信
                            </li>
                            <li class="text-gray-700">
                                <i class="fas fa-angle-right text-purple-600 mr-2"></i>
                                负载均衡场景
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Code Example -->
            <div class="card-hover rounded-xl p-8">
                <h4 class="text-xl font-bold mb-4">
                    <i class="fas fa-code text-purple-600 mr-2"></i>
                    代码示例
                </h4>
                <div class="code-block">
                    <pre><code>// 创建 